import { Injectable } from '@angular/core';
import { NzModalService } from 'ng-zorro-antd/modal';
import { Observable } from 'rxjs';
import { IdentityRoleDto } from '../proxy/identity';
import { RefSelectRoleComponent } from './ref-select-role.component';

@Injectable({
  providedIn: 'root',
})
export class RefSelectRoleService {
  private defaultWidth: number = 800;
  constructor(protected modalService: NzModalService) {}
  show(
    selectedModels?: IdentityRoleDto[],
    options?: { title?: string; width?: number; selectMode?: 'single' | 'multiple' }
  ): Observable<any> {
    let defaultTitle = `选择角色`;
    var nzTitle = !options?.title ? defaultTitle : options.title;
    var nzWidth = !options?.width ? this.defaultWidth : options.width;
    let modalRef = this.modalService.create({
      nzTitle: nzTitle,
      nzMaskClosable: false,
      nzKeyboard: true,
      nzWidth: nzWidth,
      nzComponentParams: {
        selectedModels: !selectedModels ? [] : selectedModels,
        selectMode: !options?.selectMode ? 'single' : options.selectMode,
      },
      nzContent: RefSelectRoleComponent,
    });
    return modalRef.afterClose.asObservable();
  }
}
